<script>
	import {

		alipayadsta,
		addLog,
		statusx
	} from "./api/index.js"
	import md5 from '@/utils/md5.js'
			import httpUtil from "@/utils/httpUtil.js";
	export default {
		onLaunch: function(option) {

			// #ifdef MP-ALIPAY
			if (option.query) {

console.log(option,'888888')

				my.setStorageSync({
					key: 'phone',
					data: option.query.mobile
				})
				my.setStorageSync({
					key: 'mobile',
					data: option.query.mobile
				})

				my.setStorageSync({
					key: 'orderNo',
					data: option.query.orderNo
				})
				if (option.query.a) {
					my.setStorageSync({
						key: 'a',
						data: option.query.a
					})
					statusx({
							a: httpUtil.getA(),
					}).then((res) => {
						console.log(77777777777, res)
					})
				} else {


				}

				my.setStorageSync({
					key: 'param',
					data: option.query.param
				})

			} else {
				my.getAuthCode({
					scopes: 'auth_base',
					success: (res) => {
						console.log(res)
						my.request({
							url: 'https://www.sx2b2c.com/api/rf/getAliUserid', // 请求的 URL
							method: 'POST', // POST 方法
							data: {
								code: res.authCode,
								pro_id: 51
							},
							header: {
								'Content-Type': 'application/x-www-form-urlencoded' // 设置请求头
							},
							success: (result) => {
								console.log(result)
								my.setStorageSync({
									key: 'user',
									data: result.data.data.user_id
								})
								my.setStorageSync({
									key: 'userId',
									data: result.data.data.user_id
								})
								my.setStorageSync({
									key: 'deviceid',
									data: md5.hex_md5(result.data.data.user_id)
								})

								addLog({
									v1: 1,
									v2: 100,
									text: 'a=' + uni.getStorageSync('a') + ',path=' +
										option.path + ',userid=' + uni.getStorageSync(
											'userId')+',param='+uni.getStorageSync(
											'param')
								}).then((res) => {

								})
							},
							fail: function() {

							}
						})

					},
				});
			}
			// #endif
		},
		onShow: function(option) {
my.setVisualEffectOnCapture({
			  visualEffect: 'hidden',
			  success: res => {
			    console.log(res);
			  },
			  fail: error => {
			    console.log(error);
			  },
			})
			console.log(option)
			
			if (option.referrerInfo) {
				if (option.referrerInfo.extraData.a) {

					my.setStorageSync({
						key: 'a',
						data: option.referrerInfo.extraData.a
					})
				}
			}

			// #ifdef H5
			console.log(option)
			let reg = RegExp(/extendParam/)
			console.log(reg.test(option.query.a)) //true
			var result = reg.test(option.query.a)
			if (reg.test(option.query.a) == true) {
				let a = this.$route.query.a.split("&extendParam=")
				console.log(a)

				alipayadsta({
					a: a[0]
				}).then((res) => {
					console.log(res)
				})
			} else {
				alipayadsta({
					a: option.query.a
				}).then((res) => {
					console.log(res)
				})
			}


			// #endif

			// #ifdef MP-ALIPAY

			// #endif

			if (option.query) {

				// #ifdef MP-ALIPAY

				my.setStorageSync({
					key: 'orderNo',
					data: option.query.orderNo
				})
				my.setStorageSync({
					key: 'phone',
					data: option.query.mobile
				})
				my.setStorageSync({
					key: 'mobile',
					data: option.query.mobile
				})
				if (option.query.deviceid) {

					my.setStorageSync({
						key: 'deviceid',
						data: option.query.deviceid
					})
				}
				if (option.query.a) {

					my.setStorageSync({
						key: 'a',
						data: option.query.a
					})
				
				} else {


				}

				my.setStorageSync({
					key: 'param',
					data: option.query.param
				})
			
				// #endif
				
			} else {

			}


		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@import './styles/demo';

	page {
		height: 100%;
	}
</style>